// components/search-input/index.js
Component({
  //Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors
  options: {
    addGlobalClass: true,
  },
  //传入值
  properties: {
    disabled: {
      type: Boolean,
      value: false,
    },
    // 这里定义了innerText属性，属性值可以在组件使用时指定
    placeholder: {
      type: String,
      value: '请输入',
    },
    searchValue: {
      type: String,
      value: '',
    }
  },
  data: {
    // 这里是一些组件内部数据
    // searchValue: ''
  },
  methods: {
    // 这里是一个自定义方法
    onInput(e) {
      this.setData({
        searchValue: e.detail.value
      });
    },
    clearInput(){
      console.log('清空');
      this.setData({
        searchValue: ''
      });
    },
    onClick(e){
      const searchValue = this.data.searchValue;
      this.triggerEvent('click', { keyword: searchValue });
    },
    onSearch() {
      const searchValue = this.data.searchValue;
      if (searchValue.trim() === '') {
        wx.showToast({
          title: '请输入搜索关键词',
          icon: 'none'
        });
        return;
      }
      this.triggerEvent('search', { keyword: searchValue });
    }
  }
})